package com.zbkj.admin.controller.merchant;

import com.zbkj.dal.entity.product.ProductTemplate;
import com.zbkj.dal.base.page.CommonPage;
import com.zbkj.dal.pojo.request.PageParamRequest;
import com.zbkj.dal.pojo.request.ba.ProductTemplateRequest;
import com.zbkj.dal.pojo.response.ba.ProductParameterCombineResponse;
import com.zbkj.dal.pojo.response.ba.ProductTemplateResponse;
import com.zbkj.dal.base.result.CommonResult;
import com.zbkj.service.service.ProductTemplateParameterService;
import com.zbkj.service.service.ProductTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author tianzhonghai
 * 2023/11/1 12:06
 */
@Slf4j
@RestController
@RequestMapping("api/admin/merchant/template")
@Api(tags = "商品参数")
@Validated
public class MerchantParameterTemplateController {
    @Autowired
    private ProductTemplateService productTemplateService;
    @Autowired
    private ProductTemplateParameterService productTemplateParameterService;

    /**
     * 分页查询模板
     * @param pageParamRequest
     * @return
     */
    @ApiOperation(value = "分页获取模板")
    @RequestMapping(value = "/pageProductTemplates", method = RequestMethod.POST)
    public CommonResult<CommonPage<ProductTemplate>> pageProductTemplates(PageParamRequest pageParamRequest) {
        return CommonResult.success(CommonPage.restPage(productTemplateService.pageProductTemplates(pageParamRequest)));
    }

    /**
     * 保存模板
     * @param productTemplateRequest
     * @return
     */
    @ApiOperation(value = "保存模板")
    @RequestMapping(value = "/saveProductTemplate", method = RequestMethod.POST)
    public CommonResult<Boolean> saveProductTemplate(@RequestBody ProductTemplateRequest productTemplateRequest) {
        return CommonResult.success(productTemplateService.saveProductTemplate(productTemplateRequest));
    }

    /**
     * 获取
     * @param id
     * @return
     */
    @ApiOperation(value = "获取模板")
    @RequestMapping(value = "/getProductTemplate/{id}", method = RequestMethod.GET)
    public CommonResult<ProductTemplateResponse> getProductTemplate(@PathVariable("id") Integer id) {
        return CommonResult.success(productTemplateService.getProductTemplate(id));
    }

    /**
     * 逻辑删除
     * @param id
     * @return
     */
    @ApiOperation(value = "获取模板")
    @RequestMapping(value = "/deleteProductTemplate/{id}", method = RequestMethod.DELETE)
    public CommonResult<Boolean> logicDeleteProductTemplate(@PathVariable("id") Integer id) {
        return CommonResult.success(productTemplateService.logicDeleteProductTemplate(id));
    }

    /**
     * 列出所有模板
     * @return
     */
    @ApiOperation(value = "列出所有模板")
    @RequestMapping(value = "/listProductTemplates", method = RequestMethod.GET)
    public CommonResult<List<ProductTemplate>> listProductTemplates() {
        return CommonResult.success(productTemplateService.listProductTemplates());
    }

    /**
     * 获取模板参数
     * @param id
     * @return
     */
    @ApiOperation(value = "获取模板参数")
    @RequestMapping(value = "/getProductTemplateParameters/{id}", method = RequestMethod.GET)
    public CommonResult<List<ProductParameterCombineResponse>> getProductTemplateParameters(@PathVariable("id") Integer id) {
        return CommonResult.success(productTemplateParameterService.listParameterByTemplateId(id));
    }
}
